package com.example.entity;

import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDateTime;

@Data
public class UserBalance {
    private Long id;
    
    private Long userId;
    
    private BigDecimal balance; // 账户余额
    
    private BigDecimal frozenBalance; // 冻结余额
    
    private BigDecimal totalRecharge; // 累计充值金额
    
    private BigDecimal totalConsume; // 累计消费金额
    
    private LocalDateTime createTime;
    
    private LocalDateTime updateTime;
    
    private Integer deleted;
    
    // 便捷方法
    public boolean hasEnoughBalance(BigDecimal amount) {
        return this.balance != null && this.balance.compareTo(amount) >= 0;
    }
    
    public void addBalance(BigDecimal amount) {
        if (this.balance == null) {
            this.balance = BigDecimal.ZERO;
        }
        this.balance = this.balance.add(amount);
    }
    
    public void subtractBalance(BigDecimal amount) {
        if (this.balance == null) {
            this.balance = BigDecimal.ZERO;
        }
        this.balance = this.balance.subtract(amount);
    }
    
    public void addTotalRecharge(BigDecimal amount) {
        if (this.totalRecharge == null) {
            this.totalRecharge = BigDecimal.ZERO;
        }
        this.totalRecharge = this.totalRecharge.add(amount);
    }
    
    public void addTotalConsume(BigDecimal amount) {
        if (this.totalConsume == null) {
            this.totalConsume = BigDecimal.ZERO;
        }
        this.totalConsume = this.totalConsume.add(amount);
    }
}
